//
//  CircleHeaderView.m
//  Lucky28
//
//  Created by zr on 2018/8/1.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "CircleHeaderView.h"


@interface CircleHeaderView ()

@property(nonatomic, weak)UISegmentedControl * segmentedControl;

@end

@implementation CircleHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    NSArray *segmentedArray = [NSArray arrayWithObjects:@"精华",@"最新",nil];
    
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    
    segmentedControl.frame = CGRectMake(25 * SCREENH6, 5 * SCREENH6, 320 * SCREENH6, 30 * SCREENH6);
     //    默认为no，不设置则下面一句无效
    segmentedControl.layer.masksToBounds = YES;
    //    设置圆角大小，同UIView
    segmentedControl.layer.cornerRadius = 15;
    //    边框宽度，重新画边框，若不重新画，可能会出现圆角处无边框的情况
    segmentedControl.layer.borderWidth = 1;
    //     边框颜色
    segmentedControl.layer.borderColor = MAINCOLOR.CGColor;
    
    segmentedControl.selectedSegmentIndex = 0;
    segmentedControl.tintColor = MAINCOLOR;
    
    [segmentedControl addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
    
    self.segmentedControl = segmentedControl;
    
    [self addSubview:self.segmentedControl];
}


- (void)indexDidChangeForSegmentedControl:(UISegmentedControl *)sender{

    NSInteger selecIndex = sender.selectedSegmentIndex;
    
    NSString * type;
    
    if (selecIndex == 0) {
        
        type = @"1";
    }else if (selecIndex == 1) {
        
        type = @"0";
    }
    
    NSDictionary * dict = @{@"type":type};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshCircleData" object:nil userInfo:dict];
}

@end
